home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15168 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.2 KB  |  49 lines

  1. Path: news.netins.net!trg1
  2. From: hhowe@trgnet.com (Harold Howe)
  3. Newsgroups: comp.lang.c++
  4. Subject: Is this a memory leak?
  5. Date: Wed, 03 Apr 96 22:39:41 GMT
  6. Organization: Technology Resource Group
  7. Message-ID: <4jv214$gv7@insosf1.netins.net>
  8. NNTP-Posting-Host: desm-21-08.dialup.netins.net
  9. X-Newsreader: News Xpress Version 1.0 Beta #3
  10.  
  11. Could someone please tell me if this code leaks memory
  12.  
  13. class BuriedClass
  14.   {
  15.   ...
  16.   }
  17.  
  18. class TopClass
  19.   {
  20.   private
  21.     BuriedClass *bury;
  22.   public:
  23.     TopClass::TopClass() { bury = new BuriedClass();}
  24.     shutDown             { bury = 0;}
  25.     ~TopClass            { delete bury}
  26.   }
  27.  
  28. int main(void)
  29.   {
  30.   TopClass *top = new TopClass();
  31.   top->shutDown();
  32.   delete top;
  33.   return 0;
  34.   }
  35.  
  36. Is the memory that was alloced for the buried class lost? If not please 
  37. describe how it was freed.  Does zeroing the pointer free the memory? The 
  38. delete is a waste of time on a zeroed pointer, isn't it.
  39.  
  40. All help would be greatly appreciated.  For what its worth, I am on a PC, 
  41. using BC 45 with Turbovision, and this question relates to turbovisions 
  42. shutdown function, which does this zeroing out busines that I don't 
  43. understand.
  44.  
  45. Thanks
  46. Harold Howe
  47. hhowe@trgnet.com 
  48.      
  49.